package com.jingdianjichi.subject.infra.rpc;

import com.jingdianjichi.auth.api.UserFeignService;
import com.jingdianjichi.auth.entity.AuthUserDTO;
import com.jingdianjichi.auth.entity.Result;
import com.jingdianjichi.subject.infra.rpc.entity.UserInfo;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 远程调用亲,这样就做隔离了亲
 */
@Component
public class UserRPC {

    @Resource
    private UserFeignService userFeignService;

    public UserInfo getUserInfo(String userName){
        AuthUserDTO authUserDTO=new AuthUserDTO();
        authUserDTO.setUserName(userName);

        Result<AuthUserDTO> result = userFeignService.getUserInfo(authUserDTO);

        UserInfo userInfo = new UserInfo();

        //调用成功的话我们才去放我们自己的东西
        if (!result.getSuccess()){
            return userInfo;
        }

        AuthUserDTO data = result.getData();
        //放值
        userInfo.setUserName(data.getUserName());
        userInfo.setNickName(data.getNickName());
        userInfo.setAvator(data.getAvatar());

        return userInfo;
    }

}
